<template>
  <uni-nav-bar title="车友蓝宝石调整单列表" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package datas">
    <uni-datetime-picker v-model="range" type="daterange" :border="false" :clear-icon="false" rangeSeparator="至"
      @change="change" />
  </view>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <DocumentList :orderLists="orderLists" type='车友'></DocumentList>
	 <Popu v-if="orderLists.length<1" :pageHeight="pageHeight" text="暂无车友蓝宝石调整单"></Popu>
  </scroll-view>
  <view class="add" @click="navTo('administrator/carFriend/friendList?type=2')">新增调整单</view>
</template>

<script setup lang="ts">
  import { navBack, navTo } from '@/utils/navigator';
  import Popu from '@c/earthPushing/common/popu.vue';
  import DocumentList from '@c/administrator/List/documentList.vue';
  import { ref } from 'vue';
  import { format, subDays } from 'date-fns';
  import { onShow } from '@dcloudio/uni-app';
  import { toPublish } from '@mqtt';
  import { getBillDriverGem } from '@/gql/administrator';
  import { showLoading } from '@/utils/prompt';
  /**
   * 车友账户调整单列表
   * @param {Number} pageHeight  滑动视图
   * @param {Number} lastPage  总页数
   * @param {Number} currentPage  当前页数
   * @param {Array} orderLists  车友账户列表
   */
  let now = new Date();
  let end = format(now, 'yyyy-MM-dd');
  let daysAgo = subDays(now, 6);
  let start = format(daysAgo, 'yyyy-MM-dd');
  const range = ref([start, end]);
  const pageHeight = ref();
  const lastPage = ref(1);
  const currentPage = ref(1);
  const orderLists = ref([]);
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 190;
    },
  });
  onShow(() => {
    currentPage.value = 1
    orderLists.value = []
    init()
  })
  /**
   * 初始化获取加注订单列表
   * @param page  获取当前页加注数据
   * @param start  开始时间
   * @param end  结束时间
   */
  function init() {
    showLoading()
    const payload = {
      query: getBillDriverGem,
      variables: {
        page: currentPage.value,
        start,
        end
      },
    };
    toPublish(
      'ql/control/getBillDriverGem',
      payload,
      (obj : any) => {
        uni.hideLoading();
        const { getBillDriverGem } = obj.data;
        orderLists.value = [...orderLists.value, ...getBillDriverGem.list];
        lastPage.value = getBillDriverGem.lastpage;
      }
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      init();
    }
  }
  /**
   * 时间筛选
   * @param sta  开始时间
   * @param en  结束时间
   */
  function change([sta, en] : any) {
    start = sta;
    end = en;
    currentPage.value = 1
    orderLists.value = []
    init()
  }
</script>

<style scoped lang="less">
  .add {
    width: 480rpx;
    height: 100rpx;
    background: linear-gradient(-10deg, #2C96F9, #1B91FF);
    border-radius: 5px;
    text-align: center;
    line-height: 100rpx;
    color: #fff;
    margin: 20rpx auto;
    font-size: 32rpx;
  }

  .taem:nth-of-type(1) {
    margin-top: 0px;
  }

  .top {
    margin-top: 10rpx;
  }
</style>
<style>
  .datas>>>.uni-date__x-input {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-date-x {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-icons {
    font-size: 48rpx !important;
  }
</style>